import { WeaSearchGroup,WeaFormItem } from 'ecCom';
import {WeaSwitch} from 'comsMobx';
import { Button } from 'antd';

class Condition extends React.Component{
    formParams = {};
    render(){
        const { condition, form } = this.props.requestListStore;
        const {isFormInit} = form;
        let group = [];
        const fixedFormParamsTemp = form.getFormParams();
        for(let param in fixedFormParamsTemp){
            this.formParams[param] = fixedFormParamsTemp[param];
        }
        isFormInit && condition.map((c,i) =>{
            let items = [];
            c.items.map(fields => {
                items.push({
                    com:(<WeaFormItem ecId={`${this && this.props && this.props.ecId || ''}_WeaFormItem@12v6cq@${fields.domkey[0]}`}
                        label={`${fields.label}`}
                        labelCol={{span: `${fields.labelcol}`}}
                        wrapperCol={{span: `${fields.fieldcol}`}}>
                            <WeaSwitch ecId={`${this && this.props && this.props.ecId || ''}_WeaSwitch@uqqt5t@${fields.domkey[0]}`} fieldConfig={fields} form={form} formParams={this.formParams}/>
                        </WeaFormItem>),
                    colSpan:1
                })
            });
            group.push(<WeaSearchGroup ecId={`${this && this.props && this.props.ecId || ''}_WeaSearchGroup@xarqpn@${i}`} needTigger={true} title={c.title} showGroup={c.defaultshow} items={items}/>)
        });
        return <div>{group}</div>;
    }
}

const getAdButtons = (requestListStore, ecId) => {
	const {doSearch,setShowSearchAd,clearFormFields} = requestListStore;
	return [
    (<Button ecId={`${ecId}_Button@5v7c4a@reset`} type="ghost" onClick={()=>{clearFormFields()}}>重置</Button>),
		(<Button ecId={`${ecId}_Button@3d6541@search`} type="primary" onClick={()=>{doSearch();setShowSearchAd(false);}}>搜索</Button>),
		(<Button ecId={`${ecId}_Button@pcy87k@cancel`} type="ghost" onClick={()=>{setShowSearchAd(false)}}>取消</Button>)
	];
}

export {Condition,getAdButtons}
